﻿package com.badibadi.activity;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy;
import com.amap.api.location.core.GeoPoint;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.AMap.OnMapClickListener;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.LocationSource;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.AMap.OnCameraChangeListener;
import com.amap.api.maps2d.LocationSource.OnLocationChangedListener;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.CameraPosition;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.maps2d.model.MyLocationStyle;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeAddress;
import com.amap.api.services.geocoder.GeocodeQuery;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.GeocodeSearch.OnGeocodeSearchListener;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.help.Inputtips;
import com.amap.api.services.help.Tip;
import com.amap.api.services.help.Inputtips.InputtipsListener;
import com.badibadi.infos.CreateNewClubModel;
import com.badibadi.infos.RecordModel;
import com.badibadi.infos.Results;
import com.badibadi.maputil.AMapUtil;
import com.badibadi.maputil.ToastUtil;
import com.badibadi.mytools.BitmapHelp;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.EditTextTools;
import com.badibadi.mytools.ImageTools;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.SelectPicLayoutActivity;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.XUtils;
import com.badibadi.serializable.CreationNewClubData;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;
import com.libjph.util.StringUtil;
//import com.lidroid.xutils.util.LogUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.provider.ContactsContract.CommonDataKinds.Im;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

//发源地 creation_new_apply_form 俱乐部
public class CreationNewClub2Activity extends BaseActivity implements
		OnClickListener, LocationSource, AMapLocationListener,
		OnGeocodeSearchListener, TextWatcher, OnMapClickListener,
		OnTouchListener {

	private String TAG = "CreationNewClub2Activity";
	private Button create_club_number2;
	private Intent intent = null;
	private EditText club_name, shihezhuqun, club_zongzhi;
	private Spinner quanxian;
	private ImageView iv_0, iv_1;
	private Button creation_new_apply_form;

	private String sdcard_uri_0, sdcard_uri_1;

	private String uri_0, uri_1;
	private TextView tv_up_club_pic, tv_up_bg_pic;
	private String KEY = "CreationNewClub2Activity";
	/** 保存的是上传哪一张图片 */
	private int What_A_Picture = -1;

	private static final int TAKE_PICTURE = 0;
	private static final int CHOOSE_PICTURE = 1;
	private static final int CROP = 2;
	private static final int CROP_PICTURE = 3;
	private static final int SCALE = 5;// 照片缩小比例

	private static final int IMG_CROP_HEAD = 6;
	private static final int IMG_CROP_BEIJING = 7;

	// 下面是地图的
	private AMap aMap;
	private MapView mapView;
	private OnLocationChangedListener mListener;
	private LocationManagerProxy mAMapLocationManager;
	private GeoPoint geoPoint;
	private boolean isFirstCallBack = true;// 是否为第一次回调
	// 发源地
	private AutoCompleteTextView searchText;
	private ProgressDialog progDialog = null;

	private GeocodeSearch geocoderSearch;
	private Marker geoMarker;
	private Marker regeoMarker;
	// 这里保存要上传的地址名
	private String addressName;
	// 这里保存要上传的经纬度
	private LatLonPoint latLonPoint = null;// new LatLonPoint(40.003662,
											// 116.465271)

	CreateNewClubModel createNewClubModel;
	private DisplayImageOptions options;

	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(CreationNewClub2Activity.this);

				try {
					Utils.showMessage(CreationNewClub2Activity.this,
							getResources().getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 2:

				try {
					Utils.ExitProgress_hen(CreationNewClub2Activity.this);
					Utils.ExitPrgress(CreationNewClub2Activity.this);
					boolean isSuccess = msg.getData()
							.getBoolean("isRet", false);
//					LogUtils.d("返回的路径是" + msg.getData().getString("path", ""));
					if (!StringUtil.isNullOrEmpty(msg.getData().getString(
							"path", ""))
							&& isSuccess == true) {
						String uri = msg.getData().getString("path", "");
//						LogUtils.d("sdcard1" + sdcard_uri_0 + "  sdcard2"
//								+ sdcard_uri_1 + " " + What_A_Picture);
						if (!StringUtil.isNullOrEmpty(sdcard_uri_0)
								&& What_A_Picture == 0) {

							iv_0.setImageURI(Uri.parse(sdcard_uri_0));
							// new BitmapHelp().displayImage(
							// CreationNewClub2Activity.this, iv_0,
							// Constants.BadiDownImgUrl + uri
							// + Constants.App9block);
							// ImageLoader.getInstance().displayImage(Constants.BadiDownImgUrl+"/"+uri,
							// iv_0, options);
							uri_0 = msg.getData().getString("path", "");
							createNewClubModel.setLogo("" + uri_0);// 封面
//							LogUtils.d("运行了1");
						} else if (!StringUtil.isNullOrEmpty(sdcard_uri_1)
								&& What_A_Picture == 1) {
							iv_1.setImageURI(Uri.parse(sdcard_uri_1));
							// new BitmapHelp().displayImage(
							// CreationNewClub2Activity.this, iv_1,
							// Constants.BadiDownImgUrl + uri
							// + Constants.App9block);
							// ImageLoader.getInstance().displayImage(Constants.BadiDownImgUrl+"/"+uri,
							// iv_1, options);
							uri_1 = msg.getData().getString("path", "");
//							LogUtils.d("运行了2");
							createNewClubModel.setRoom_head("" + uri_1);// 背景图
						}
					}
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 3:
				Utils.ExitPrgress(CreationNewClub2Activity.this);
				try {
					Utils.showMessage(CreationNewClub2Activity.this,
							getResources().getString(R.string.l_xa10));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 4:
				Utils.ExitPrgress(CreationNewClub2Activity.this);
				// try {
				// Utils.showMessage(CreationNewClub2Activity.this,
				// results2.getRetmsg());
				// } catch (Exception e) {
				// // TODO: handle exception
				// }
			default:
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.creation_new_club2);
//		LogUtils.d("我想知道activity中的onCreate运行了？");
		this.findViewById(R.id.return_btn).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						finish();
					}
				});
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();

		mapView = (MapView) findViewById(R.id.map);
		mapView.onCreate(savedInstanceState);// 此方法必须重写
		createNewClubModel = new CreateNewClubModel();
		createNewClubModel = (CreateNewClubModel) getIntent()
				.getSerializableExtra("createNewClubModel");

		init();

	}

	private void init() {
		// TODO Auto-generated method stub
		shihezhuqun = (EditText) this.findViewById(R.id.shihezhuqun);
		quanxian = (Spinner) this.findViewById(R.id.quanxian);
		club_zongzhi = (EditText) this.findViewById(R.id.club_zongzhi);
		club_zongzhi.setOnTouchListener(this);
		this.findViewById(R.id.crNewClubdingwei).setOnClickListener(this);
		this.findViewById(R.id.club_zongzhi_linear).setOnClickListener(this);
		searchText = (AutoCompleteTextView) this.findViewById(R.id.fayuandi);
		searchText.addTextChangedListener(this);
		create_club_number2 = (Button) findViewById(R.id.create_club_number2);
		create_club_number2.setOnClickListener(CreationNewClub2Activity.this);
		club_name = (EditText) this.findViewById(R.id.club_name);
		iv_0 = (ImageView) this.findViewById(R.id.iv_0);
		iv_1 = (ImageView) this.findViewById(R.id.iv_1);
		iv_0.setOnClickListener(CreationNewClub2Activity.this);
		iv_1.setOnClickListener(CreationNewClub2Activity.this);
		creation_new_apply_form = (Button) findViewById(R.id.creation_new_apply_form);
		creation_new_apply_form.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(CreationNewClub2Activity.this,
						AddApplyFormActivity.class);
				// startActivity(intent);
				startActivityForResult(intent, 10);
			}
		});
		createNewClubModel.setIs_apply("0");
		progDialog = new ProgressDialog(this);
		geocoderSearch = new GeocodeSearch(this);
		geocoderSearch.setOnGeocodeSearchListener(this);
		tv_up_club_pic = (TextView) this.findViewById(R.id.up_club_pic);
		tv_up_club_pic.setOnClickListener(CreationNewClub2Activity.this);
		tv_up_bg_pic = (TextView) this.findViewById(R.id.up_bg_pic);
		tv_up_bg_pic.setOnClickListener(CreationNewClub2Activity.this);

		if (aMap == null) {
			aMap = mapView.getMap();

			geoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
					.icon(BitmapDescriptorFactory
							.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
			regeoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
					.icon(BitmapDescriptorFactory
							.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
			setUpMap();
		}
	}

	private void setUpMap() {
		// TODO Auto-generated method stub
		// 自定义系统定位小蓝点
		// MyLocationStyle myLocationStyle = new MyLocationStyle();
		// myLocationStyle.myLocationIcon(BitmapDescriptorFactory
		// .fromResource(R.drawable.location_marker));// 设置小蓝点的图标
		// myLocationStyle.strokeColor(Color.BLACK);// 设置圆形的边框颜色
		// myLocationStyle.radiusFillColor(Color.argb(100, 0, 0, 180));//
		// 设置圆形的填充颜色
		// // myLocationStyle.anchor(int,int)//设置小蓝点的锚点
		// myLocationStyle.strokeWidth(1.0f);// 设置圆形的边框粗细
		aMap.moveCamera(CameraUpdateFactory
				.newLatLngZoom(Constants.CHENGDU, 12));// 设置指定的可视区域地图

		// aMap.setMyLocationStyle(myLocationStyle);
		aMap.setOnMapClickListener(this);// 点击地图上的
		aMap.setLocationSource(this);// 设置定位监听
		aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
		aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
		// aMap.setMyLocationType()
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		super.onActivityResult(requestCode, resultCode, data);
//		LogUtils.d("339=" + data);

		if (resultCode == Activity.RESULT_OK && requestCode == IMG_CROP_HEAD) {
			if (data != null) {
				sdcard_uri_0 = data
						.getStringExtra(SelectPicLayoutActivity.KEY_PHOTO_PATH);

				UpSDcardPicture(sdcard_uri_0);
//				LogUtils.d("345");
			}

			// iv_0.setImageURI(Uri.parse(uri_0));

		}
		if (resultCode == Activity.RESULT_OK && requestCode == IMG_CROP_BEIJING) {
			if (data != null) {
				sdcard_uri_1 = data
						.getStringExtra(SelectPicLayoutActivity.KEY_PHOTO_PATH);
				UpSDcardPicture(sdcard_uri_1);
//				LogUtils.d("356");
			}

			// iv_1.setImageURI(Uri.parse(uri_1));
		}
//		LogUtils.d("347");
		if (requestCode == 10 && resultCode == 10) {
			if (data != null) {
				String result__ = data.getStringExtra("result");
				if (result__ != null && result__.equals("success")) {
					createNewClubModel.setIs_apply("1");
				} else {
					createNewClubModel.setIs_apply("0");
					Toast.makeText(getApplicationContext(),
							getResources().getString(R.string.l_xb62), 0)
							.show();
				}
			}

		}

	}

	/**
	 * 
	 * @param sdcard_uri_02
	 */
	private void UpSDcardPicture(String sdcard_uri_02) {
		// TODO Auto-generated method stub
		if (!StringUtil.isNullOrEmpty(createNewClubModel.getUid()))
			XUtils.UpImg(sdcard_uri_02, CreationNewClub2Activity.this,
					mHandler, createNewClubModel.getUid(), 2);

	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onResume() {
		super.onResume();
		mapView.onResume();
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onPause() {
		super.onPause();
		mapView.onPause();
		deactivate();
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		mapView.onSaveInstanceState(outState);
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onDestroy() {
		super.onDestroy();
		mapView.onDestroy();
	}

	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub

	}

	/**
	 * 定位成功后回调函数
	 */
	@Override
	public void onLocationChanged(AMapLocation aLocation) {
		//    
		if (mListener != null && aLocation != null) {

			//    
			// "aLocation.getLatitude()--->"+aLocation.getLatitude()+"  aLocation.getLongitude()===>"+aLocation.getLongitude());
			mListener.onLocationChanged(aLocation);// 显示系统小蓝点

			// geoPoint=new GeoPoint((int) (aLocation.getLatitude() * 1E6),
			// (int) (aLocation.getLongitude() * 1E6));
			// //用给定的经纬度构造一个GeoPoint，单位是微度 (度 * 1E6)
			// CameraUpdateFactory a=CameraUpdateFactory.newLatLngZoom(new
			// LatLng(arg0, arg1), arg1)

			if (isFirstCallBack == true) {
				aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
						aLocation.getLatitude(), aLocation.getLongitude()), 12));// 设置指定的可视区域地图
				isFirstCallBack = false;
				latLonPoint = new LatLonPoint(aLocation.getLatitude(),
						aLocation.getLongitude());
//				   
				getAddress(new LatLonPoint(aLocation.getLatitude(),
						aLocation.getLongitude()));

//				   
			}
		}
	}

	/**
	 * 激活定位
	 */
	@Override
	public void activate(OnLocationChangedListener listener) {
		mListener = listener;
		if (mAMapLocationManager == null) {
			mAMapLocationManager = LocationManagerProxy.getInstance(this);
			/*
			 * mAMapLocManager.setGpsEnable(false);
			 * 1.0.2版本新增方法，设置true表示混合定位中包含gps定位，false表示纯网络定位，默认是true Location
			 * API定位采用GPS和网络混合定位方式
			 * ，第一个参数是定位provider，第二个参数时间最短是2000毫秒，第三个参数距离间隔单位是米，第四个参数是定位监听者
			 */
			mAMapLocationManager.requestLocationUpdates(
					LocationProviderProxy.AMapNetwork, 2000, 10, this);
		}
	}

	/**
	 * 停止定位
	 */
	@Override
	public void deactivate() {
		mListener = null;
		if (mAMapLocationManager != null) {
			mAMapLocationManager.removeUpdates(this);
			mAMapLocationManager.destory();
		}
		mAMapLocationManager = null;
	}

	/**
	 * 显示进度条对话框
	 */
	public void showDialog() {
		progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progDialog.setIndeterminate(false);
		progDialog.setCancelable(true);
		progDialog.setMessage(getResources().getString(R.string.l_xb63));
		progDialog.show();
	}

	/**
	 * 响应逆地理编码
	 */
	public void getAddress(final LatLonPoint latLonPoint) {
		showDialog();
		RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,
				GeocodeSearch.AMAP);// 第一个参数表示一个Latlng，第二参数表示范围多少米，第三个参数表示是火系坐标系还是GPS原生坐标系
		geocoderSearch.getFromLocationAsyn(query);// 设置同步逆地理编码请求
//		   
	}

	/**
	 * 响应地理编码
	 */
	public void getLatlon(final String name) {
		showDialog();
		GeocodeQuery query = new GeocodeQuery(name, null);// 第一个参数表示地址，第二个参数表示查询城市，中文或者中文全拼，citycode、adcode，
		geocoderSearch.getFromLocationNameAsyn(query);// 设置同步地理编码请求
	}

	/**
	 * 地理编码查询回调
	 */
	@Override
	public void onGeocodeSearched(GeocodeResult result, int rCode) {
		// // TODO Auto-generated method stub
		dismissDialog();
		if (rCode == 0) {
			if (result != null && result.getGeocodeAddressList() != null
					&& result.getGeocodeAddressList().size() > 0) {
				GeocodeAddress address = result.getGeocodeAddressList().get(0);
				aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
						AMapUtil.convertToLatLng(address.getLatLonPoint()), 15));
				geoMarker.setPosition(AMapUtil.convertToLatLng(address
						.getLatLonPoint()));
				addressName = "经纬度值:" + address.getLatLonPoint() + "\n位置描述:"
						+ address.getFormatAddress();
				// 这里保存要上传的经纬度
				latLonPoint = address.getLatLonPoint();

//				   
//						+ "///" + latLonPoint.getLongitude());

				ShowToast(CreationNewClub2Activity.this, addressName);
			} else {
				ToastUtil.show(CreationNewClub2Activity.this,
						R.string.no_result);
			}

		} else if (rCode == 27) {
			ToastUtil.show(CreationNewClub2Activity.this,
					R.string.error_network);
		} else if (rCode == 32) {
			ToastUtil.show(CreationNewClub2Activity.this, R.string.error_key);
		} else {
			ToastUtil.show(CreationNewClub2Activity.this,
					getString(R.string.error_other) + rCode);
		}
	}

	// /**
	// * 逆地理编码回调
	// */
	@Override
	public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
		// // TODO Auto-generated method stub
		dismissDialog();
		if (rCode == 0) {
			if (result != null && result.getRegeocodeAddress() != null
					&& result.getRegeocodeAddress().getFormatAddress() != null) {
				addressName = result.getRegeocodeAddress().getFormatAddress()
						+ "附近";
				if (addressName != ""
						&& searchText.getText().toString().trim() != "") {
					searchText.setText(""
							+ result.getRegeocodeAddress().getFormatAddress());
				}
				// aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
				// AMapUtil.convertToLatLng(latLonPoint), 15));
				regeoMarker.setPosition(AMapUtil.convertToLatLng(latLonPoint));
				ToastUtil.show(CreationNewClub2Activity.this, addressName);
			} else {
				ToastUtil.show(CreationNewClub2Activity.this,
						R.string.no_result);
			}
		} else if (rCode == 27) {
			ToastUtil.show(CreationNewClub2Activity.this,
					R.string.error_network);
		} else if (rCode == 32) {
			ToastUtil.show(CreationNewClub2Activity.this, R.string.error_key);
		} else {
			ToastUtil.show(CreationNewClub2Activity.this,
					getString(R.string.error_other) + rCode);
		}
//		   
	}

	/**
	 * 隐藏进度条对话框
	 */
	public void dismissDialog() {
		if (progDialog != null) {
			progDialog.dismiss();
		}
	}

	// TextWatcher
	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub

	}

	// TextWatcher
	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub

	}

	// TextWatcher
	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		// TODO Auto-generated method stub
		String newText = s.toString().trim();
		Inputtips inputTips = new Inputtips(CreationNewClub2Activity.this,
				new InputtipsListener() {

					@Override
					public void onGetInputtips(List<Tip> tipList, int rCode) {
						if (rCode == 0) {// 正确返回
							List<String> listString = new ArrayList<String>();
							for (int i = 0; i < tipList.size(); i++) {
								listString.add(tipList.get(i).getName());
							}
							ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(
									getApplicationContext(),
									R.layout.route_inputs, listString);
							searchText.setAdapter(aAdapter);
							aAdapter.notifyDataSetChanged();
						}
					}
				});
		try {
			inputTips.requestInputtips(newText, null);// 第一个参数表示提示关键字，第二个参数默认代表全国，也可以为城市区号

		} catch (AMapException e) {
			   
		}
	}

	// 点击地图的上东西后回调
	@Override
	public void onMapClick(LatLng latlng) {
		// TODO Auto-generated method stub
		if (aMap != null && latlng != null) {
			aMap.clear();
			// MarkerOptions markerOptions=new MarkerOptions();
			// markerOptions.
			geoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
					.icon(BitmapDescriptorFactory
							.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
			// aMap.addMarker(new MarkerOptions());
			geoMarker.setPosition(latlng);
			getAddress(AMapUtil.convertToLatLonPoint(latlng));
			aMap.invalidate();
			latLonPoint = AMapUtil.convertToLatLonPoint(latlng);
//			   
//					"address+====>" + addressName + " latLonPoint--->"
//							+ latLonPoint.getLatitude() + ","
//							+ latLonPoint.getLongitude());

		}
	}

	// 创建俱乐部2传递的
	// class CreationNewClub2Data implements Serializable
	// {
	// /**
	// *
	// */
	// private static final long serialVersionUID = 8908189037929812913L;
	// // public String club_Name;
	// // public String fayuandi;
	// // public String Shihezhuqun;
	// // public String Quanxian;
	// // public String ClubZongzhi;
	// // public Drawable Iv_0;
	// // public Drawable Iv_1;
	// public CreationNewClub2Data()
	// {
	// // club_Name=club_name.getText().toString().trim();
	// // fayuandi=searchText.getText().toString().trim();
	// // Shihezhuqun=shihezhuqun.getText().toString().trim();
	// // Quanxian=quanxian.getSelectedItem().toString();
	// // ClubZongzhi=club_zongzhi.getText().toString().trim();
	// // Iv_0=iv_0.getDrawable();
	// // Iv_1=iv_1.getDrawable();
	//
	// }
	//
	// }
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.create_club_number2:

//			   

			if (PanduanIsChange()) {
				intent = new Intent(CreationNewClub2Activity.this,
						CreationNewClub3Activity.class);

				String cname = club_name.getText().toString().trim();
				if (cname.length() >= 3) {
					if (!(cname.substring(cname.length() - 3, cname.length())
							.equals(getResources().getString(R.string.club)))) {
						club_name.setText(""
								+ club_name.getText().toString().trim());
					}
				} else if (cname.length() < 3) {
					club_name.setText(""
							+ club_name.getText().toString().trim());
				}
				createNewClubModel.setName(""
						+ club_name.getText().toString().trim());// 俱乐部名称
//				   
				createNewClubModel.setMap_x("" + latLonPoint.getLatitude());// 纬度
				createNewClubModel.setMap_y("" + latLonPoint.getLongitude());// 经度度
				createNewClubModel.setSuit_persons(""
						+ shihezhuqun.getText().toString());// 适合族群
				createNewClubModel.setOriginate_address(searchText.getText()
						.toString());// 发源地
//				   
//						+ "/" + quanxian.getSelectedItem());
				createNewClubModel.setRoom_limit(""
						+ (quanxian.getSelectedItemId() + 1));// 空间权限0 所有人，1会员
				createNewClubModel.setInfo(""
						+ club_zongzhi.getText().toString().trim());// 俱乐部宗旨

				intent.putExtra("createNewClubModel", createNewClubModel);

				// CreationNewClubData cr=new CreationNewClubData();
				// cr.setClub_Type(""+getIntent().getStringExtra("CreationNewClubActivity"));
				// //    
				// cr.setClub_Name(""+club_name.getText().toString().trim());
				// cr.setFayuandi(""+searchText.getText().toString().trim());
				// cr.setShihezhuqun(""+shihezhuqun.getText().toString().trim());
				// cr.setClubZongzhi(""+club_zongzhi.getText().toString().trim());
				//    
				// "这是"+ImageTools.loadBitmapFromView(CreationNewClub2Activity.this,
				// iv_0));
				// if(uri_0!="")
				// cr.setClub_fengmian(uri_0);
				// cr.setClub_beijingtu(uri_1);
				// Bundle bundle=new Bundle();
				// bundle.putSerializable("CreationNewClub2Activity",cr);
				// intent.putExtras(bundle);
//				   
				startActivity(intent);
				overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
				CreationNewClub2Activity.this.finish();
			}
			break;
		case R.id.up_club_pic:
			What_A_Picture = 0;
			// 截图后显示
			// showPicturePicker(CreationNewClub2Activity.this, true);
			Intent intent = new Intent(CreationNewClub2Activity.this,
					SelectPicLayoutActivity.class);
			startActivityForResult(intent, IMG_CROP_HEAD);

			break;
		case R.id.up_bg_pic:
			What_A_Picture = 1;
			// 截图后显示
			// showPicturePicker(CreationNewClub2Activity.this, true);
			Intent intent2 = new Intent(CreationNewClub2Activity.this,
					SelectPicLayoutActivity.class);
			intent2.putExtra("Cutting", "yes");// 传入是否需要裁剪的参数，传则不需要，不传则需要
			startActivityForResult(intent2, IMG_CROP_BEIJING);
			break;
		case R.id.iv_0:
			What_A_Picture = 0;
			// 截图后显示
			Intent intent3 = new Intent(CreationNewClub2Activity.this,
					SelectPicLayoutActivity.class);
			startActivityForResult(intent3, IMG_CROP_HEAD);
			break;
		case R.id.iv_1:
			What_A_Picture = 1;
			// 截图后显示
			// showPicturePicker(CreationNewClub2Activity.this, true);
			Intent intent4 = new Intent(CreationNewClub2Activity.this,
					SelectPicLayoutActivity.class);
			intent4.putExtra("Cutting", "yes");// 传入是否需要裁剪的参数，传则不需要，不传则需要
			startActivityForResult(intent4, IMG_CROP_BEIJING);
			break;
		case R.id.crNewClubdingwei:
			// getAddress();
			getLatlon("" + searchText.getText().toString().trim());
			break;
		case R.id.club_zongzhi_linear:
			club_zongzhi.setFocusable(true);
			club_zongzhi.setFocusableInTouchMode(true);
			club_zongzhi.requestFocus();
			EditTextTools.CloseOrConsultingEvaluation(club_zongzhi);
			break;
		}
	}

	/**
	 * 判断数据是否可以传递
	 * 
	 * @return
	 */
	private boolean PanduanIsChange() {
		// TODO Auto-generated method stub

		if ("".equals(club_name.getText().toString().trim())) {
			Toast.makeText(
					CreationNewClub2Activity.this,
					"" + getResources().getString(R.string.PleaseEnterClubName),
					Toast.LENGTH_SHORT).show();
			return false;
		} else if ("".equals(searchText.getText().toString().trim())) {
			Toast.makeText(CreationNewClub2Activity.this,
					"" + getResources().getString(R.string.IndexAddressError),
					Toast.LENGTH_SHORT).show();
			return false;
		} else if ("".equals(shihezhuqun.getText().toString().trim())) {
			Toast.makeText(
					CreationNewClub2Activity.this,
					""
							+ getResources().getString(
									R.string.PleaseFillInTheSuitableForEthnic),
					Toast.LENGTH_SHORT).show();
			return false;
		} else if (uri_0 == null || uri_0 == "") {
			Toast.makeText(
					CreationNewClub2Activity.this,
					""
							+ getResources().getString(
									R.string.PleaseUpClubFengmian),
					Toast.LENGTH_SHORT).show();
			return false;
		} else if ("".equals(club_zongzhi.getText().toString().trim())) {
			Toast.makeText(
					CreationNewClub2Activity.this,
					""
							+ getResources().getString(
									R.string.PleaseFillInTheClubContent),
					Toast.LENGTH_SHORT).show();
			return false;
		} else if (uri_1 == null || uri_1 == "") {
			Toast.makeText(
					CreationNewClub2Activity.this,
					"" + getResources().getString(R.string.PleaseUpClubBeijing),
					Toast.LENGTH_SHORT).show();
			return false;
		} else if (latLonPoint == null) {
//			   
			Toast.makeText(CreationNewClub2Activity.this,
					getResources().getString(R.string.l_xb64),
					Toast.LENGTH_SHORT).show();
			return false;
		} else if (searchText.getText().toString() == null) {
//			   
			Toast.makeText(CreationNewClub2Activity.this,
					getResources().getString(R.string.l_xb65),
					Toast.LENGTH_SHORT).show();
			return false;
		}

		// cr.setClub_Name(""+club_name.getText().toString().trim());
		// cr.setFayuandi(""+searchText.getText().toString().trim());
		// cr.setShihezhuqun(""+shihezhuqun.getText().toString().trim());
		// cr.setClubZongzhi(""+club_zongzhi.getText().toString().trim());
		// cr.setClub_fengmian(uri_0);
		// cr.setClub_beijingtu(uri_1);

		return true;
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (v.getId()) {
		case R.id.club_zongzhi:
			// case R.id.ActiveContent_linear:
			v.getParent().requestDisallowInterceptTouchEvent(true);
//			   
			switch (event.getAction() & MotionEvent.ACTION_MASK) {
			case MotionEvent.ACTION_UP:
				v.getParent().requestDisallowInterceptTouchEvent(false);
				break;
			}
			break;

		default:
			break;
		}
		return false;
	}

}
